

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>cup package &mdash; cup 1.7.0 documentation</title>
  

  
  
  
  

  

  
  
    

  

  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../genindex/" />
    <link rel="search" title="Search" href="../search/" />
    <link rel="next" title="cup.net package" href="../cup.net/" />
    <link rel="prev" title="Welcome to cup’s documentation!" href="../" /> 

  
  <script src="../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../" class="icon icon-home"> cup
          

          
          </a>

          
            
            
              <div class="version">
                1.7
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="#">cup package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#subpackages">Subpackages</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../cup.net/">cup.net package</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cup.res/">cup.res package</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cup.util/">cup.util package</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cup.services/">cup.services package</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cup.shell/">cup.shell package</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cup.storage/">cup.storage package</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cup.jenkinslib/">cup.jenkinslib package</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cup.web/">cup.web package</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup.cache">cup.cache module</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup.const">cup.const module</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup.decorators">cup.decorators module</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup.err">cup.err module</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup.exfile">cup.exfile module</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup.flag">cup.flag module</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup.log">cup.log module</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup.mail">cup.mail module</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup.platforms">cup.platforms module</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup.thread">cup.thread module</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup.timeplus">cup.timeplus module</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup.unittest">cup.unittest module</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup.version">cup.version module</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cup">Module contents</a></li>
</ul>
</li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../">cup</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../">Docs</a> &raquo;</li>
        
      <li>cup package</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/cup.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="cup-package">
<h1>cup package<a class="headerlink" href="#cup-package" title="Permalink to this headline">¶</a></h1>
<div class="section" id="subpackages">
<h2>Subpackages<a class="headerlink" href="#subpackages" title="Permalink to this headline">¶</a></h2>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../cup.net/">cup.net package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../cup.net/#subpackages">Subpackages</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../cup.net.async/">cup.net.async package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../cup.net.async/#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="../cup.net.async/#module-cup.net.async.common">cup.net.async.common module</a></li>
<li class="toctree-l4"><a class="reference internal" href="../cup.net.async/#module-cup.net.async.conn">cup.net.async.conn module</a></li>
<li class="toctree-l4"><a class="reference internal" href="../cup.net.async/#module-cup.net.async.context">cup.net.async.context module</a></li>
<li class="toctree-l4"><a class="reference internal" href="../cup.net.async/#module-cup.net.async.msg">cup.net.async.msg module</a></li>
<li class="toctree-l4"><a class="reference internal" href="../cup.net.async/#module-cup.net.async.msgcenter">cup.net.async.msgcenter module</a></li>
<li class="toctree-l4"><a class="reference internal" href="../cup.net.async/#module-cup.net.async">Module contents</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../cup.net/#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.net/#module-cup.net.route">cup.net.route module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.net/#module-cup.net">Module contents</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../cup.res/">cup.res package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../cup.res/#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.res/#module-cup.res.linux">cup.res.linux module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.res/#module-cup.res.mac">cup.res.mac module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.res/#module-cup.res">Module contents</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../cup.util/">cup.util package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../cup.util/#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.util/#module-cup.util.conf">cup.util.conf module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.util/#module-cup.util.constants">cup.util.constants module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.util/#module-cup.util.context">cup.util.context module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.util/#module-cup.util.misc">cup.util.misc module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.util/#module-cup.util">Module contents</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../cup.services/">cup.services package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../cup.services/#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.services/#module-cup.services.autowait">cup.services.autowait module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.services/#module-cup.services.buffers">cup.services.buffers module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.services/#module-cup.services.executor">cup.services.executor module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.services/#module-cup.services.generator">cup.services.generator module</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../cup.services/#class-cgeneratorman-object">class CGeneratorMan(object)</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../cup.services/#module-cup.services.heartbeat">cup.services.heartbeat module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.services/#module-cup.services.msgbroker">cup.services.msgbroker module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.services/#module-cup.services.serializer">cup.services.serializer module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.services/#module-cup.services.threadpool">cup.services.threadpool module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.services/#module-cup.services">Module contents</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../cup.shell/">cup.shell package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../cup.shell/#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.shell/#module-cup.shell.expect">cup.shell.expect module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.shell/#module-cup.shell.oper">cup.shell.oper module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.shell/#module-cup.shell">Module contents</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../cup.storage/">cup.storage package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../cup.storage/#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.storage/#module-cup.storage.obj">cup.storage.obj module</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cup.storage/#module-cup.storage">Module contents</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../cup.jenkinslib/">cup.jenkinslib package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../cup.jenkinslib/#subpackages">Subpackages</a><ul class="simple">
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../cup.jenkinslib/#module-cup.jenkinslib">Module contents</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../cup.web/">cup.web package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../cup.web/#module-cup.web">Module contents</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="section" id="submodules">
<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="module-cup.cache">
<span id="cup-cache-module"></span><h2>cup.cache module<a class="headerlink" href="#module-cup.cache" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">description:</th><td class="field-body">decorators related module</td>
</tr>
</tbody>
</table>
<dl class="class">
<dt id="cup.cache.KvCache">
<em class="property">class </em><code class="descclassname">cup.cache.</code><code class="descname">KvCache</code><a class="reference internal" href="../_modules/cup/cache/#KvCache"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.cache.KvCache" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Key-Value Cache object</p>
<dl class="method">
<dt id="cup.cache.KvCache.cleanup_expired">
<code class="descname">cleanup_expired</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/cache/#KvCache.cleanup_expired"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.cache.KvCache.cleanup_expired" title="Permalink to this definition">¶</a></dt>
<dd><p>Delete all expired items</p>
</dd></dl>

<dl class="method">
<dt id="cup.cache.KvCache.clear">
<code class="descname">clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/cache/#KvCache.clear"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.cache.KvCache.clear" title="Permalink to this definition">¶</a></dt>
<dd><p>remove all kv cache inside.</p>
</dd></dl>

<dl class="method">
<dt id="cup.cache.KvCache.get">
<code class="descname">get</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/cache/#KvCache.get"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.cache.KvCache.get" title="Permalink to this definition">¶</a></dt>
<dd><p>Get your cache with key.
If the cache is expired, it will return None.
If the key does not exist, it will return None.</p>
</dd></dl>

<dl class="method">
<dt id="cup.cache.KvCache.get_expired">
<code class="descname">get_expired</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/cache/#KvCache.get_expired"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.cache.KvCache.get_expired" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">A dict.
Return expired items. Return type is a dict (<blockquote>
<div><dl class="docutils">
<dt>{</dt>
<dd>‘key’ : (value, expire_time)</dd>
</dl>
<p>}</p>
</div></blockquote>
<p>)</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cup.cache.KvCache.set">
<code class="descname">set</code><span class="sig-paren">(</span><em>kvlist</em>, <em>expire_sec=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/cache/#KvCache.set"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.cache.KvCache.set" title="Permalink to this definition">¶</a></dt>
<dd><p>set cache with kvlist</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>kvlist</strong> – kvlist is a dict that contains your cache.</li>
<li><strong>expire_sec</strong> – if expire_sec is None, the cache will never expire.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cup.cache.KvCache.stat">
<code class="descname">stat</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/cache/#KvCache.stat"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.cache.KvCache.stat" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">a tuple with (item_num, expired_num)</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-cup.const">
<span id="cup-const-module"></span><h2>cup.const module<a class="headerlink" href="#module-cup.const" title="Permalink to this headline">¶</a></h2>
<p>internal const class</p>
<dl class="exception">
<dt id="cup.const.ConstError">
<em class="property">exception </em><code class="descclassname">cup.const.</code><code class="descname">ConstError</code><span class="sig-paren">(</span><em>msg=''</em><span class="sig-paren">)</span><a class="headerlink" href="#cup.const.ConstError" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.err.BaseCupException" title="cup.err.BaseCupException"><code class="xref py py-class docutils literal notranslate"><span class="pre">cup.err.BaseCupException</span></code></a></p>
<p>const error</p>
</dd></dl>

</div>
<div class="section" id="module-cup.decorators">
<span id="cup-decorators-module"></span><h2>cup.decorators module<a class="headerlink" href="#module-cup.decorators" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">description:</th><td class="field-body">decorators related module</td>
</tr>
</tbody>
</table>
<dl class="class">
<dt id="cup.decorators.Singleton">
<em class="property">class </em><code class="descclassname">cup.decorators.</code><code class="descname">Singleton</code><span class="sig-paren">(</span><em>cls</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/decorators/#Singleton"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.decorators.Singleton" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Make your class singeton</p>
<p>example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cup</span> <span class="k">import</span> <span class="n">decorators</span>

<span class="nd">@decorators</span><span class="o">.</span><span class="n">Singleton</span>
<span class="k">class</span> <span class="nc">YourClass</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="k">pass</span>
</pre></div>
</div>
</dd></dl>

<dl class="class">
<dt id="cup.decorators.TraceUsedTime">
<em class="property">class </em><code class="descclassname">cup.decorators.</code><code class="descname">TraceUsedTime</code><span class="sig-paren">(</span><em>b_print_stdout=False</em>, <em>enter_msg=''</em>, <em>leave_msg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/decorators/#TraceUsedTime"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.decorators.TraceUsedTime" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Trace used time inside a function.</p>
<p>Will print to LOGFILE if you initialized logging with cup.log.init_comlog.</p>
<p>example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">time</span>

<span class="kn">from</span> <span class="nn">cup</span> <span class="k">import</span> <span class="n">decorators</span>

<span class="nd">@decorators</span><span class="o">.</span><span class="n">TraceUsedTime</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">test</span><span class="p">():</span>
    <span class="nb">print</span> <span class="s1">&#39;test&#39;</span>
    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>


<span class="c1"># trace something with context. E.g. event_id</span>
<span class="k">def</span> <span class="nf">_test_trace_time_map</span><span class="p">(</span><span class="n">sleep_time</span><span class="p">):</span>
    <span class="nb">print</span> <span class="s2">&quot;ready to work&quot;</span>
    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">sleep_time</span><span class="p">)</span>


<span class="n">traced_test_trace_time_map</span> <span class="o">=</span> <span class="n">decorators</span><span class="o">.</span><span class="n">TraceUsedTime</span><span class="p">(</span>
    <span class="n">b_print_stdout</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
    <span class="n">enter_msg</span><span class="o">=</span><span class="s1">&#39;event_id: 0x12345&#39;</span><span class="p">,</span>
    <span class="n">leave_msg</span><span class="o">=</span><span class="s1">&#39;event_id: 0x12345&#39;</span>
<span class="p">)(</span><span class="n">_test_trace_time_map</span><span class="p">)</span>
<span class="n">traced_test_trace_time_map</span><span class="p">(</span><span class="n">sleep_time</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="cup.decorators.needlinux">
<code class="descclassname">cup.decorators.</code><code class="descname">needlinux</code><span class="sig-paren">(</span><em>function</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/decorators/#needlinux"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.decorators.needlinux" title="Permalink to this definition">¶</a></dt>
<dd><p>make sure the func is only used on linux.
Raise cup.err.DecoratorException otherwise.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Platform:</th><td class="field-body">Linux</td>
</tr>
</tbody>
</table>
<p>example</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cup</span> <span class="k">import</span> <span class="n">decorators</span>
<span class="nd">@decorators</span><span class="o">.</span><span class="n">needlinux</span>
<span class="k">def</span> <span class="nf">your_func</span><span class="p">():</span>
    <span class="k">pass</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="cup.decorators.needposix">
<code class="descclassname">cup.decorators.</code><code class="descname">needposix</code><span class="sig-paren">(</span><em>function</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/decorators/#needposix"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.decorators.needposix" title="Permalink to this definition">¶</a></dt>
<dd><p>only support posix</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Platform:</th><td class="field-body">Posix compatible</td>
</tr>
</tbody>
</table>
<p>example</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cup</span> <span class="k">import</span> <span class="n">decorators</span>
<span class="nd">@decorators</span><span class="o">.</span><span class="n">needposix</span>
<span class="k">def</span> <span class="nf">your_func</span><span class="p">():</span>
    <span class="k">pass</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="cup.decorators.needmac">
<code class="descclassname">cup.decorators.</code><code class="descname">needmac</code><span class="sig-paren">(</span><em>function</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/decorators/#needmac"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.decorators.needmac" title="Permalink to this definition">¶</a></dt>
<dd><p>only support macOS</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Platform:</th><td class="field-body">macOS</td>
</tr>
</tbody>
</table>
<p>example</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cup</span> <span class="k">import</span> <span class="n">decorators</span>
<span class="nd">@decorators</span><span class="o">.</span><span class="n">needmac</span>
<span class="k">def</span> <span class="nf">your_func</span><span class="p">():</span>
    <span class="k">pass</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="cup.decorators.py_versioncheck">
<code class="descclassname">cup.decorators.</code><code class="descname">py_versioncheck</code><span class="sig-paren">(</span><em>function</em>, <em>version</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/decorators/#py_versioncheck"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.decorators.py_versioncheck" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Platform:</th><td class="field-body">any platform + any functions in python</td>
</tr>
<tr class="field-even field"><th class="field-name">Parameters:</th><td class="field-body"><strong>version</strong> – The python on the OS should be &gt;= param version.
<em>E.g. version=(‘2’, ‘7’, ‘0’)</em>
OS python version should &gt;= 2.7.0</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="module-cup.err">
<span id="cup-err-module"></span><h2>cup.err module<a class="headerlink" href="#module-cup.err" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">description:</th><td class="field-body">error related module</td>
</tr>
</tbody>
</table>
<dl class="exception">
<dt id="cup.err.BaseCupException">
<em class="property">exception </em><code class="descclassname">cup.err.</code><code class="descname">BaseCupException</code><span class="sig-paren">(</span><em>msg</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/err/#BaseCupException"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.err.BaseCupException" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">exceptions.Exception</span></code></p>
<p>base cup Exception. All other cup Exceptions will inherit this.</p>
</dd></dl>

<dl class="exception">
<dt id="cup.err.DecoratorException">
<em class="property">exception </em><code class="descclassname">cup.err.</code><code class="descname">DecoratorException</code><span class="sig-paren">(</span><em>msg</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/err/#DecoratorException"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.err.DecoratorException" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.err.BaseCupException" title="cup.err.BaseCupException"><code class="xref py py-class docutils literal notranslate"><span class="pre">cup.err.BaseCupException</span></code></a></p>
</dd></dl>

<dl class="exception">
<dt id="cup.err.LoggerException">
<em class="property">exception </em><code class="descclassname">cup.err.</code><code class="descname">LoggerException</code><span class="sig-paren">(</span><em>msg</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/err/#LoggerException"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.err.LoggerException" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.err.BaseCupException" title="cup.err.BaseCupException"><code class="xref py py-class docutils literal notranslate"><span class="pre">cup.err.BaseCupException</span></code></a></p>
<p>Exception for logging, especially for cup.log</p>
</dd></dl>

<dl class="exception">
<dt id="cup.err.ResException">
<em class="property">exception </em><code class="descclassname">cup.err.</code><code class="descname">ResException</code><span class="sig-paren">(</span><em>msg</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/err/#ResException"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.err.ResException" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.err.BaseCupException" title="cup.err.BaseCupException"><code class="xref py py-class docutils literal notranslate"><span class="pre">cup.err.BaseCupException</span></code></a></p>
<p>Resource releated Exception</p>
</dd></dl>

<dl class="exception">
<dt id="cup.err.NoSuchProcess">
<em class="property">exception </em><code class="descclassname">cup.err.</code><code class="descname">NoSuchProcess</code><span class="sig-paren">(</span><em>pid</em>, <em>str_process_name</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/err/#NoSuchProcess"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.err.NoSuchProcess" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.err.ResException" title="cup.err.ResException"><code class="xref py py-class docutils literal notranslate"><span class="pre">cup.err.ResException</span></code></a></p>
<p>No such Process Exception</p>
</dd></dl>

<dl class="exception">
<dt id="cup.err.AccessDenied">
<em class="property">exception </em><code class="descclassname">cup.err.</code><code class="descname">AccessDenied</code><span class="sig-paren">(</span><em>str_resouce</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/err/#AccessDenied"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.err.AccessDenied" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.err.ResException" title="cup.err.ResException"><code class="xref py py-class docutils literal notranslate"><span class="pre">cup.err.ResException</span></code></a></p>
<p>Access Denied</p>
</dd></dl>

<dl class="exception">
<dt id="cup.err.NetException">
<em class="property">exception </em><code class="descclassname">cup.err.</code><code class="descname">NetException</code><span class="sig-paren">(</span><em>msg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/err/#NetException"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.err.NetException" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.err.BaseCupException" title="cup.err.BaseCupException"><code class="xref py py-class docutils literal notranslate"><span class="pre">cup.err.BaseCupException</span></code></a></p>
<p>Network releated Exception</p>
</dd></dl>

<dl class="exception">
<dt id="cup.err.AsyncMsgError">
<em class="property">exception </em><code class="descclassname">cup.err.</code><code class="descname">AsyncMsgError</code><span class="sig-paren">(</span><em>msg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/err/#AsyncMsgError"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.err.AsyncMsgError" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.err.NetException" title="cup.err.NetException"><code class="xref py py-class docutils literal notranslate"><span class="pre">cup.err.NetException</span></code></a></p>
<p>cup.net.async msg related Exception</p>
</dd></dl>

<dl class="exception">
<dt id="cup.err.ThreadTermException">
<em class="property">exception </em><code class="descclassname">cup.err.</code><code class="descname">ThreadTermException</code><span class="sig-paren">(</span><em>msg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/err/#ThreadTermException"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.err.ThreadTermException" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.err.BaseCupException" title="cup.err.BaseCupException"><code class="xref py py-class docutils literal notranslate"><span class="pre">cup.err.BaseCupException</span></code></a></p>
<p>Thread termination error</p>
</dd></dl>

<dl class="exception">
<dt id="cup.err.LockFileError">
<em class="property">exception </em><code class="descclassname">cup.err.</code><code class="descname">LockFileError</code><span class="sig-paren">(</span><em>msg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/err/#LockFileError"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.err.LockFileError" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.err.BaseCupException" title="cup.err.BaseCupException"><code class="xref py py-class docutils literal notranslate"><span class="pre">cup.err.BaseCupException</span></code></a></p>
</dd></dl>

<dl class="exception">
<dt id="cup.err.NotImplementedYet">
<em class="property">exception </em><code class="descclassname">cup.err.</code><code class="descname">NotImplementedYet</code><span class="sig-paren">(</span><em>msg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/err/#NotImplementedYet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.err.NotImplementedYet" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.err.BaseCupException" title="cup.err.BaseCupException"><code class="xref py py-class docutils literal notranslate"><span class="pre">cup.err.BaseCupException</span></code></a></p>
<p>Not implemented yet</p>
</dd></dl>

<dl class="exception">
<dt id="cup.err.ConfigError">
<em class="property">exception </em><code class="descclassname">cup.err.</code><code class="descname">ConfigError</code><span class="sig-paren">(</span><em>msg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/err/#ConfigError"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.err.ConfigError" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.err.BaseCupException" title="cup.err.BaseCupException"><code class="xref py py-class docutils literal notranslate"><span class="pre">cup.err.BaseCupException</span></code></a></p>
</dd></dl>

</div>
<div class="section" id="module-cup.exfile">
<span id="cup-exfile-module"></span><h2>cup.exfile module<a class="headerlink" href="#module-cup.exfile" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">description:</th><td class="field-body">file related functions</td>
</tr>
</tbody>
</table>
<dl class="class">
<dt id="cup.exfile.LockFile">
<em class="property">class </em><code class="descclassname">cup.exfile.</code><code class="descname">LockFile</code><span class="sig-paren">(</span><em>fpath</em>, <em>locktype=2</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/exfile/#LockFile"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.exfile.LockFile" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>lock file class</p>
<dl class="method">
<dt id="cup.exfile.LockFile.lock">
<code class="descname">lock</code><span class="sig-paren">(</span><em>blocking=True</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/exfile/#LockFile.lock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.exfile.LockFile.lock" title="Permalink to this definition">¶</a></dt>
<dd><p>lock the file</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>blocking</strong> – If blocking is True, will block there until cup gets the lock.
True by default.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">return False if locking fails</td>
</tr>
<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><strong>Exception</strong> – raise cup.err.LockFileError if blocking is False and
the lock action failed</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cup.exfile.LockFile.unlock">
<code class="descname">unlock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/exfile/#LockFile.unlock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.exfile.LockFile.unlock" title="Permalink to this definition">¶</a></dt>
<dd><p>unlock the locked file</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="cup.exfile.TempFile">
<em class="property">class </em><code class="descclassname">cup.exfile.</code><code class="descname">TempFile</code><span class="sig-paren">(</span><em>filedir</em>, <em>prefix=''</em>, <em>suffix=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/exfile/#TempFile"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.exfile.TempFile" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>tempfile, the temp file will be deleted immediately after the lifetime.</p>
<p>You can use TempFile like the original Python File Object.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">tmp</span> <span class="o">=</span> <span class="n">TempFile</span><span class="p">(</span><span class="s1">&#39;./&#39;</span><span class="p">)</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">write</span> <span class="o">/</span> <span class="n">read</span> <span class="o">/</span><span class="n">seek</span> <span class="o">/</span> <span class="n">etc</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="module-cup.flag">
<span id="cup-flag-module"></span><h2>cup.flag module<a class="headerlink" href="#module-cup.flag" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">description:</th><td class="field-body"></td>
</tr>
</tbody>
</table>
<dl class="class">
<dt id="cup.flag.TypeMan">
<em class="property">class </em><code class="descclassname">cup.flag.</code><code class="descname">TypeMan</code><a class="reference internal" href="../_modules/cup/flag/#TypeMan"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.flag.TypeMan" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">cup.flag.BaseMan</span></code></p>
<p>msg flag class</p>
</dd></dl>

</div>
<div class="section" id="module-cup.log">
<span id="cup-log-module"></span><h2>cup.log module<a class="headerlink" href="#module-cup.log" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">description:</th><td class="field-body">common log related module</td>
</tr>
</tbody>
</table>
<dl class="function">
<dt id="cup.log.debug">
<code class="descclassname">cup.log.</code><code class="descname">debug</code><span class="sig-paren">(</span><em>msg</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/logging/#debug"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.log.debug" title="Permalink to this definition">¶</a></dt>
<dd><p>Log a message with severity ‘DEBUG’ on the root logger.</p>
</dd></dl>

<dl class="function">
<dt id="cup.log.info">
<code class="descclassname">cup.log.</code><code class="descname">info</code><span class="sig-paren">(</span><em>msg</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/logging/#info"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.log.info" title="Permalink to this definition">¶</a></dt>
<dd><p>Log a message with severity ‘INFO’ on the root logger.</p>
</dd></dl>

<dl class="function">
<dt id="cup.log.warn">
<code class="descclassname">cup.log.</code><code class="descname">warn</code><span class="sig-paren">(</span><em>msg</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#cup.log.warn" title="Permalink to this definition">¶</a></dt>
<dd><p>Log a message with severity ‘WARNING’ on the root logger.</p>
</dd></dl>

<dl class="function">
<dt id="cup.log.critical">
<code class="descclassname">cup.log.</code><code class="descname">critical</code><span class="sig-paren">(</span><em>msg</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/logging/#critical"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.log.critical" title="Permalink to this definition">¶</a></dt>
<dd><p>Log a message with severity ‘CRITICAL’ on the root logger.</p>
</dd></dl>

<dl class="function">
<dt id="cup.log.init_comlog">
<code class="descclassname">cup.log.</code><code class="descname">init_comlog</code><span class="sig-paren">(</span><em>loggername</em>, <em>loglevel=20</em>, <em>logfile='cup.log'</em>, <em>logtype=0</em>, <em>maxlogsize=1073741824</em>, <em>bprint_console=False</em>, <em>gen_wf=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/log/#init_comlog"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.log.init_comlog" title="Permalink to this definition">¶</a></dt>
<dd><p>Initialize your logging</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>loggername</strong> – Unique logger name</li>
<li><strong>loglevel</strong> – 4 default levels: log.DEBUG log.INFO log.ERROR log.CRITICAL</li>
<li><strong>logfile</strong> – log file. Will try to create it if no existence</li>
<li><strong>logtype</strong> – <p>Two type candidiates: log.ROTATION and log.INFINITE</p>
<p>log.ROTATION will let logfile switch to a new one (30 files at most).
When logger reaches the 30th logfile, will overwrite from the
oldest to the most recent.</p>
<p>log.INFINITE will write on the logfile infinitely</p>
</li>
<li><strong>maxlogsize</strong> – maxmum log size with byte</li>
<li><strong>b_printcmd</strong> – print to stdout or not?</li>
<li><strong>gen_wf</strong> – print log msges with level &gt;= WARNING to file (${logfile}.wf)</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p><em>E.g.</em></p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">from</span> <span class="nn">cup</span> <span class="k">import</span> <span class="n">log</span>
<span class="n">log</span><span class="o">.</span><span class="n">init_comlog</span><span class="p">(</span>
    <span class="s1">&#39;test&#39;</span><span class="p">,</span>
    <span class="n">log</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">,</span>
    <span class="s1">&#39;/home/work/test/test.log&#39;</span><span class="p">,</span>
    <span class="n">log</span><span class="o">.</span><span class="n">ROTATION</span><span class="p">,</span>
    <span class="mi">1024</span><span class="p">,</span>
    <span class="kc">False</span>
<span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;test xxx&#39;</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s1">&#39;test critical&#39;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="cup.log.setloglevel">
<code class="descclassname">cup.log.</code><code class="descname">setloglevel</code><span class="sig-paren">(</span><em>logginglevel</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/log/#setloglevel"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.log.setloglevel" title="Permalink to this definition">¶</a></dt>
<dd><p>change log level during runtime</p>
</dd></dl>

<dl class="function">
<dt id="cup.log.reinit_comlog">
<code class="descclassname">cup.log.</code><code class="descname">reinit_comlog</code><span class="sig-paren">(</span><em>loggername</em>, <em>loglevel=20</em>, <em>logfile='cup.log'</em>, <em>logtype=0</em>, <em>maxlogsize=1073741824</em>, <em>bprint_console=False</em>, <em>gen_wf=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/log/#reinit_comlog"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.log.reinit_comlog" title="Permalink to this definition">¶</a></dt>
<dd><p>reinitalize logging system, paramters same to init_comlog.
reinit_comlog will reset all logging parameters，
Make sure you used a different loggername from the old one!</p>
</dd></dl>

<dl class="function">
<dt id="cup.log.get_inited_loggername">
<code class="descclassname">cup.log.</code><code class="descname">get_inited_loggername</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/log/#get_inited_loggername"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.log.get_inited_loggername" title="Permalink to this definition">¶</a></dt>
<dd><p>get initialized logger name</p>
</dd></dl>

<dl class="function">
<dt id="cup.log.parse">
<code class="descclassname">cup.log.</code><code class="descname">parse</code><span class="sig-paren">(</span><em>logline</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/log/#parse"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.log.parse" title="Permalink to this definition">¶</a></dt>
<dd><p>return a dict if the line is valid.
Otherwise, return None</p>
<dl class="docutils">
<dt>::</dt>
<dd><dl class="first docutils">
<dt>dict_info:= {</dt>
<dd>‘loglevel’: ‘DEBUG’,
‘date’: ‘2015-10-14’,
‘time’: ‘16:12:22,924’,
‘pid’: 8808,
‘tid’: 1111111,
‘srcline’: ‘util.py:33’,
‘msg’: ‘this is the log content’</dd>
</dl>
<p class="last">}</p>
</dd>
</dl>
</dd></dl>

<dl class="function">
<dt id="cup.log.backtrace_info">
<code class="descclassname">cup.log.</code><code class="descname">backtrace_info</code><span class="sig-paren">(</span><em>msg</em>, <em>back_trace_len=0</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/log/#backtrace_info"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.log.backtrace_info" title="Permalink to this definition">¶</a></dt>
<dd><p>info with backtrace support</p>
</dd></dl>

<dl class="function">
<dt id="cup.log.backtrace_debug">
<code class="descclassname">cup.log.</code><code class="descname">backtrace_debug</code><span class="sig-paren">(</span><em>msg</em>, <em>back_trace_len=0</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/log/#backtrace_debug"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.log.backtrace_debug" title="Permalink to this definition">¶</a></dt>
<dd><p>debug with backtrace support</p>
</dd></dl>

<dl class="function">
<dt id="cup.log.backtrace_error">
<code class="descclassname">cup.log.</code><code class="descname">backtrace_error</code><span class="sig-paren">(</span><em>msg</em>, <em>back_trace_len=0</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/log/#backtrace_error"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.log.backtrace_error" title="Permalink to this definition">¶</a></dt>
<dd><p>error msg with backtarce support</p>
</dd></dl>

<dl class="function">
<dt id="cup.log.backtrace_critical">
<code class="descclassname">cup.log.</code><code class="descname">backtrace_critical</code><span class="sig-paren">(</span><em>msg</em>, <em>back_trace_len=0</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/log/#backtrace_critical"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.log.backtrace_critical" title="Permalink to this definition">¶</a></dt>
<dd><p>logging.CRITICAL with backtrace support</p>
</dd></dl>

</div>
<div class="section" id="module-cup.mail">
<span id="cup-mail-module"></span><h2>cup.mail module<a class="headerlink" href="#module-cup.mail" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">description:</th><td class="field-body"><p class="first">mail related modules.</p>
<p class="last"><strong>Recommand using SmtpMailer</strong></p>
</td>
</tr>
</tbody>
</table>
<dl class="function">
<dt id="cup.mail.mutt_sendmail">
<code class="descclassname">cup.mail.</code><code class="descname">mutt_sendmail</code><span class="sig-paren">(</span><em>tostr</em>, <em>subject</em>, <em>body</em>, <em>attach</em>, <em>content_is_html=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/mail/#mutt_sendmail"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.mail.mutt_sendmail" title="Permalink to this definition">¶</a></dt>
<dd><p>Plz notice this function is not recommanded to use. Use SmtpMailer instead.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>exec_cwd</strong> – exec working directory. Plz use</li>
<li><strong>tostr</strong> – recipt list, separated by ,</li>
<li><strong>subject</strong> – subject</li>
<li><strong>body</strong> – email content</li>
<li><strong>attach</strong> – email attachment</li>
<li><strong>content_is_html</strong> – is htm mode opened</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">return True on success, False otherwise</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="class">
<dt id="cup.mail.SmtpMailer">
<em class="property">class </em><code class="descclassname">cup.mail.</code><code class="descname">SmtpMailer</code><span class="sig-paren">(</span><em>sender</em>, <em>server='mail2-in.baidu.com'</em>, <em>port=25</em>, <em>is_html=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/mail/#SmtpMailer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.mail.SmtpMailer" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>sender</strong> – mail sender</li>
<li><strong>server</strong> – smtp的mailserver</li>
<li><strong>port</strong> – port</li>
<li><strong>is_html</strong> – is html enabled</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>smtp server examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cup</span> <span class="k">import</span> <span class="n">mail</span>
<span class="n">mailer</span> <span class="o">=</span> <span class="n">mail</span><span class="o">.</span><span class="n">SmtpMailer</span><span class="p">(</span>
    <span class="s1">&#39;xxx@xxx.com&#39;</span><span class="p">,</span>
    <span class="s1">&#39;xxxx.smtp.xxx.com&#39;</span><span class="p">,</span>
    <span class="n">is_html</span><span class="o">=</span><span class="kc">True</span>
<span class="p">)</span>
<span class="n">mailer</span><span class="o">.</span><span class="n">sendmail</span><span class="p">(</span>
    <span class="p">[</span>
        <span class="s1">&#39;maguannan&#39;</span><span class="p">,</span>
        <span class="s1">&#39;liuxuan05&#39;</span><span class="p">,</span>
        <span class="s1">&#39;zhaominghao&#39;</span>
    <span class="p">],</span>
    <span class="s1">&#39;test_img&#39;</span><span class="p">,</span>
    <span class="p">(</span>
        <span class="s1">&#39;testset &lt;img src=&quot;cid:screenshot.png&quot;&gt;&lt;/img&gt;&#39;</span>
    <span class="p">),</span>
    <span class="p">[</span>
        <span class="s1">&#39;/home/work/screenshot.png&#39;</span><span class="p">,</span>
        <span class="s1">&#39;../abc.zip&#39;</span>
    <span class="p">]</span>
<span class="p">)</span>
</pre></div>
</div>
<dl class="method">
<dt id="cup.mail.SmtpMailer.sendmail">
<code class="descname">sendmail</code><span class="sig-paren">(</span><em>recipients</em>, <em>subject=''</em>, <em>body=''</em>, <em>attachments=None</em>, <em>cc=None</em>, <em>bcc=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/mail/#SmtpMailer.sendmail"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.mail.SmtpMailer.sendmail" title="Permalink to this definition">¶</a></dt>
<dd><p>send mail</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>recipients</strong> – “list” of recipients. See the example above</li>
<li><strong>subject</strong> – subject</li>
<li><strong>body</strong> – body of the mail</li>
<li><strong>attachments</strong> – “list” of attachments. Plz use absolute file path!</li>
<li><strong>cc</strong> – cc list</li>
<li><strong>bcc</strong> – bcc list</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">return (True, None) on success, return (False, error_msg) otherwise</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cup.mail.SmtpMailer.setup">
<code class="descname">setup</code><span class="sig-paren">(</span><em>sender</em>, <em>server</em>, <em>port=25</em>, <em>is_html=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/mail/#SmtpMailer.setup"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.mail.SmtpMailer.setup" title="Permalink to this definition">¶</a></dt>
<dd><p>change parameters during run-time</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-cup.platforms">
<span id="cup-platforms-module"></span><h2>cup.platforms module<a class="headerlink" href="#module-cup.platforms" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">description:</th><td class="field-body">cross-platform functions related module</td>
</tr>
</tbody>
</table>
<dl class="function">
<dt id="cup.platforms.is_linux">
<code class="descclassname">cup.platforms.</code><code class="descname">is_linux</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/platforms/#is_linux"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.platforms.is_linux" title="Permalink to this definition">¶</a></dt>
<dd><p>Check if you are running on Linux.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">True or False</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="cup.platforms.is_windows">
<code class="descclassname">cup.platforms.</code><code class="descname">is_windows</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/platforms/#is_windows"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.platforms.is_windows" title="Permalink to this definition">¶</a></dt>
<dd><p>Check if you are running on Windows.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">True or False</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="cup.platforms.is_mac">
<code class="descclassname">cup.platforms.</code><code class="descname">is_mac</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/platforms/#is_mac"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.platforms.is_mac" title="Permalink to this definition">¶</a></dt>
<dd><p>is mac os</p>
</dd></dl>

</div>
<div class="section" id="module-cup.thread">
<span id="cup-thread-module"></span><h2>cup.thread module<a class="headerlink" href="#module-cup.thread" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">description:</th><td class="field-body">cup thread module</td>
</tr>
</tbody>
</table>
<dl class="function">
<dt id="cup.thread.async_raise">
<code class="descclassname">cup.thread.</code><code class="descname">async_raise</code><span class="sig-paren">(</span><em>tid</em>, <em>exctype</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/thread/#async_raise"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.thread.async_raise" title="Permalink to this definition">¶</a></dt>
<dd><p>Raises an exception in the threads with id tid</p>
</dd></dl>

<dl class="class">
<dt id="cup.thread.CupThread">
<em class="property">class </em><code class="descclassname">cup.thread.</code><code class="descname">CupThread</code><span class="sig-paren">(</span><em>group=None</em>, <em>target=None</em>, <em>name=None</em>, <em>args=()</em>, <em>kwargs=None</em>, <em>verbose=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/thread/#CupThread"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.thread.CupThread" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Thread</span></code></p>
<p>CupThread is a sub-class inherited from threading.Thread;</p>
<p>CupThread has 3 more features:</p>
<ol class="arabic simple">
<li><dl class="first docutils">
<dt>raise_exc, to send a raise-exception signal to the thread,</dt>
<dd>TRY to let the thread raise an exception.</dd>
</dl>
</li>
<li>get_my_tid, get thread id</li>
<li>terminate, to stop the thread</li>
</ol>
<dl class="docutils">
<dt>Notice if a thread in busy running under kernel-sysmode, it may not</dt>
<dd>response to the signals! Thus, it may not raise any exception/terminate
even though cup has send a CupThread signal!</dd>
</dl>
<dl class="method">
<dt id="cup.thread.CupThread.get_my_tid">
<code class="descname">get_my_tid</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/thread/#CupThread.get_my_tid"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.thread.CupThread.get_my_tid" title="Permalink to this definition">¶</a></dt>
<dd><p>return thread id</p>
</dd></dl>

<dl class="method">
<dt id="cup.thread.CupThread.raise_exc">
<code class="descname">raise_exc</code><span class="sig-paren">(</span><em>exctype</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/thread/#CupThread.raise_exc"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.thread.CupThread.raise_exc" title="Permalink to this definition">¶</a></dt>
<dd><p>asynchrously send ‘raise exception’ signal to the thread.
:param exctype:</p>
<blockquote>
<div>raise Exception, exctype type is class</div></blockquote>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">return 1 on success. 0 otherwise.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cup.thread.CupThread.terminate">
<code class="descname">terminate</code><span class="sig-paren">(</span><em>times=15</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/thread/#CupThread.terminate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.thread.CupThread.terminate" title="Permalink to this definition">¶</a></dt>
<dd><p>asynchrously terminate the thread.</p>
<p>Return True if the termination is successful or the thread is already
stopped. Return False, otherwise.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Times:</th><td class="field-body">retry times until call for failure.</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="cup.thread.RWLock">
<em class="property">class </em><code class="descclassname">cup.thread.</code><code class="descname">RWLock</code><a class="reference internal" href="../_modules/cup/thread/#RWLock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.thread.RWLock" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>read/write lock</p>
<dl class="method">
<dt id="cup.thread.RWLock.acquire_readlock">
<code class="descname">acquire_readlock</code><span class="sig-paren">(</span><em>wait_time=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/thread/#RWLock.acquire_readlock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.thread.RWLock.acquire_readlock" title="Permalink to this definition">¶</a></dt>
<dd><p>Acquire readlock. Wait_time same to wait_time for acquire_writelock</p>
</dd></dl>

<dl class="method">
<dt id="cup.thread.RWLock.acquire_writelock">
<code class="descname">acquire_writelock</code><span class="sig-paren">(</span><em>wait_time=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/thread/#RWLock.acquire_writelock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.thread.RWLock.acquire_writelock" title="Permalink to this definition">¶</a></dt>
<dd><p>Acquire write lock. If wait_time is not None and wait_time &gt;=0,
cup will wait until wait_time passes. If the call timeouts and
cannot get the lock, will raise RuntimeError</p>
</dd></dl>

<dl class="method">
<dt id="cup.thread.RWLock.release_readlock">
<code class="descname">release_readlock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/thread/#RWLock.release_readlock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.thread.RWLock.release_readlock" title="Permalink to this definition">¶</a></dt>
<dd><p>release read lock</p>
</dd></dl>

<dl class="method">
<dt id="cup.thread.RWLock.release_writelock">
<code class="descname">release_writelock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/thread/#RWLock.release_writelock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.thread.RWLock.release_writelock" title="Permalink to this definition">¶</a></dt>
<dd><p>release write lock</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-cup.timeplus">
<span id="cup-timeplus-module"></span><h2>cup.timeplus module<a class="headerlink" href="#module-cup.timeplus" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">desc:</th><td class="field-body">time related module. looking forward to accepting new patches</td>
</tr>
</tbody>
</table>
<dl class="function">
<dt id="cup.timeplus.get_str_now">
<code class="descclassname">cup.timeplus.</code><code class="descname">get_str_now</code><span class="sig-paren">(</span><em>fmt='%Y-%m-%d-%H-%M-%S'</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/timeplus/#get_str_now"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.timeplus.get_str_now" title="Permalink to this definition">¶</a></dt>
<dd><p>return string of ‘now’</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>fmt</strong> – print-format, ‘%Y-%m-%d-%H-%M-%S’ by default</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="module-cup.unittest">
<span id="cup-unittest-module"></span><h2>cup.unittest module<a class="headerlink" href="#module-cup.unittest" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">desc:</th><td class="field-body">unittest module</td>
</tr>
</tbody>
</table>
<dl class="function">
<dt id="cup.unittest.assert_true">
<code class="descclassname">cup.unittest.</code><code class="descname">assert_true</code><span class="sig-paren">(</span><em>val</em>, <em>errmsg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#assert_true"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.assert_true" title="Permalink to this definition">¶</a></dt>
<dd><p>If val is not True, assert False and print to stdout.</p>
<p>Plz notice, log.critical(errmsg) will be invoked if logging system has
been initialized with cup.log.init_comlog.</p>
</dd></dl>

<dl class="function">
<dt id="cup.unittest.assert_false">
<code class="descclassname">cup.unittest.</code><code class="descname">assert_false</code><span class="sig-paren">(</span><em>val</em>, <em>errmsg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#assert_false"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.assert_false" title="Permalink to this definition">¶</a></dt>
<dd><p>val should be False. Assert False otherwise.</p>
</dd></dl>

<dl class="function">
<dt id="cup.unittest.assert_eq">
<code class="descclassname">cup.unittest.</code><code class="descname">assert_eq</code><span class="sig-paren">(</span><em>val</em>, <em>exp</em>, <em>errmsg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#assert_eq"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.assert_eq" title="Permalink to this definition">¶</a></dt>
<dd><p>if val != exp, aseert False and print errmsg</p>
</dd></dl>

<dl class="function">
<dt id="cup.unittest.assert_not_eq">
<code class="descclassname">cup.unittest.</code><code class="descname">assert_not_eq</code><span class="sig-paren">(</span><em>val</em>, <em>exp</em>, <em>errmsg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#assert_not_eq"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.assert_not_eq" title="Permalink to this definition">¶</a></dt>
<dd><p>assert not equal to</p>
</dd></dl>

<dl class="function">
<dt id="cup.unittest.assert_eq_one">
<code class="descclassname">cup.unittest.</code><code class="descname">assert_eq_one</code><span class="sig-paren">(</span><em>val</em>, <em>array</em>, <em>errmsg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#assert_eq_one"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.assert_eq_one" title="Permalink to this definition">¶</a></dt>
<dd><p>assert val equals one of the items in the [array]</p>
</dd></dl>

<dl class="function">
<dt id="cup.unittest.assert_lt">
<code class="descclassname">cup.unittest.</code><code class="descname">assert_lt</code><span class="sig-paren">(</span><em>val</em>, <em>exp</em>, <em>errmsg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#assert_lt"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.assert_lt" title="Permalink to this definition">¶</a></dt>
<dd><p>assert_lt, expect val &lt; exp</p>
</dd></dl>

<dl class="function">
<dt id="cup.unittest.assert_gt">
<code class="descclassname">cup.unittest.</code><code class="descname">assert_gt</code><span class="sig-paren">(</span><em>val</em>, <em>exp</em>, <em>errmsg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#assert_gt"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.assert_gt" title="Permalink to this definition">¶</a></dt>
<dd><p>assert_gt, expect val &gt; exp</p>
</dd></dl>

<dl class="function">
<dt id="cup.unittest.assert_ge">
<code class="descclassname">cup.unittest.</code><code class="descname">assert_ge</code><span class="sig-paren">(</span><em>val</em>, <em>exp</em>, <em>errmsg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#assert_ge"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.assert_ge" title="Permalink to this definition">¶</a></dt>
<dd><p>expect val &gt;= exp</p>
</dd></dl>

<dl class="function">
<dt id="cup.unittest.assert_le">
<code class="descclassname">cup.unittest.</code><code class="descname">assert_le</code><span class="sig-paren">(</span><em>val</em>, <em>exp</em>, <em>errmsg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#assert_le"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.assert_le" title="Permalink to this definition">¶</a></dt>
<dd><p>expect val &lt;= exp</p>
</dd></dl>

<dl class="function">
<dt id="cup.unittest.assert_ne">
<code class="descclassname">cup.unittest.</code><code class="descname">assert_ne</code><span class="sig-paren">(</span><em>val</em>, <em>exp</em>, <em>errmsg=''</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#assert_ne"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.assert_ne" title="Permalink to this definition">¶</a></dt>
<dd><p>expect val != exp</p>
</dd></dl>

<dl class="class">
<dt id="cup.unittest.CUTCase">
<em class="property">class </em><code class="descclassname">cup.unittest.</code><code class="descname">CUTCase</code><span class="sig-paren">(</span><em>logfile='./test.log'</em>, <em>b_logstd=False</em>, <em>b_debug=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#CUTCase"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.CUTCase" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>CUTCase is compatible with nosetests. You can inherit this class
and implement your own TestClass.</p>
<p>Notice class method [set_result] will set case status to True/False after
executing the case. Then you can get case status in teardown through
calling class method [get_result]</p>
<dl class="method">
<dt id="cup.unittest.CUTCase.get_result">
<code class="descname">get_result</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#CUTCase.get_result"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.CUTCase.get_result" title="Permalink to this definition">¶</a></dt>
<dd><p>get case status during case teardown</p>
</dd></dl>

<dl class="method">
<dt id="cup.unittest.CUTCase.set_result">
<code class="descname">set_result</code><span class="sig-paren">(</span><em>b_result</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#CUTCase.set_result"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.CUTCase.set_result" title="Permalink to this definition">¶</a></dt>
<dd><p>set case running status</p>
</dd></dl>

<dl class="method">
<dt id="cup.unittest.CUTCase.setup">
<code class="descname">setup</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#CUTCase.setup"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.CUTCase.setup" title="Permalink to this definition">¶</a></dt>
<dd><p>set up</p>
</dd></dl>

<dl class="method">
<dt id="cup.unittest.CUTCase.teardown">
<code class="descname">teardown</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#CUTCase.teardown"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.CUTCase.teardown" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="cup.unittest.CUTCase.test_run">
<code class="descname">test_run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#CUTCase.test_run"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.CUTCase.test_run" title="Permalink to this definition">¶</a></dt>
<dd><p>test_run function</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="cup.unittest.CCaseExecutor">
<em class="property">class </em><code class="descclassname">cup.unittest.</code><code class="descname">CCaseExecutor</code><a class="reference internal" href="../_modules/cup/unittest/#CCaseExecutor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.CCaseExecutor" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Executor class for executing CUTCase test cases. See the example below</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>

<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">logging</span>

<span class="kn">import</span> <span class="nn">cup</span>
<span class="kn">import</span> <span class="nn">sb_global</span>

<span class="kn">from</span> <span class="nn">nfsinit</span> <span class="k">import</span> <span class="n">CClearMan</span>
<span class="kn">from</span> <span class="nn">nfs</span> <span class="k">import</span> <span class="n">CNfs</span>
<span class="kn">from</span> <span class="nn">cli</span> <span class="k">import</span> <span class="n">CCli</span>

<span class="k">class</span> <span class="nc">TestMyCase</span><span class="p">(</span><span class="n">cup</span><span class="o">.</span><span class="n">unittest</span><span class="o">.</span><span class="n">CUTCase</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">logfile</span><span class="o">=</span><span class="n">sb_global</span><span class="o">.</span><span class="n">G_CASE_RUN_LOG</span><span class="p">,</span>
            <span class="n">b_logstd</span><span class="o">=</span><span class="kc">False</span>
        <span class="p">)</span>
        <span class="n">cup</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span> <span class="s1">&#39;Start to run &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="vm">__file__</span> <span class="p">)</span> <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_cli</span> <span class="o">=</span> <span class="n">CCli</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_nfs</span> <span class="o">=</span> <span class="n">CNfs</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_uniq_strman</span> <span class="o">=</span> <span class="n">cup</span><span class="o">.</span><span class="n">util</span><span class="o">.</span><span class="n">CGeneratorMan</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_clearman</span> <span class="o">=</span> <span class="n">CClearMan</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">setup</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">str_uniq</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_uniq_strman</span><span class="o">.</span><span class="n">get_uniqname</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_workfolder</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">())</span>                     <span class="o">+</span> <span class="s1">&#39;/&#39;</span> <span class="o">+</span> <span class="n">str_uniq</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_work_remote_folder</span> <span class="o">=</span>                     <span class="bp">self</span><span class="o">.</span><span class="n">_nfs</span><span class="o">.</span><span class="n">translate_path_into_remote_under_rw_folder</span><span class="p">(</span>
            <span class="n">str_uniq</span>
            <span class="p">)</span>
        <span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_workfolder</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_clearman</span><span class="o">.</span><span class="n">addfolder</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_workfolder</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_check_filemd5</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">):</span>
        <span class="n">ret</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">system</span><span class="p">(</span><span class="s1">&#39;/usr/bin/diff --brief </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">)</span> <span class="p">)</span>
        <span class="n">cup</span><span class="o">.</span><span class="n">unittest</span><span class="o">.</span><span class="n">assert_eq</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span> <span class="n">ret</span> <span class="p">)</span>

    <span class="k">def</span> <span class="nf">test_run</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c1">#</span>
        <span class="c1"># @author: maguannan</span>
        <span class="c1">#</span>
        <span class="n">inited_bigfile</span> <span class="o">=</span> <span class="n">sb_global</span><span class="o">.</span><span class="n">G_NFS_DISK_RD</span> <span class="o">+</span>                     <span class="n">sb_global</span><span class="o">.</span><span class="n">G_TEST_BIGFILE</span>
        <span class="n">bigfile</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_workfolder</span> <span class="o">+</span>                     <span class="s1">&#39;/test_big_file_offsite_write_random_write&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tmpfile</span> <span class="o">=</span> <span class="n">sb_global</span><span class="o">.</span><span class="n">G_TMP4USE</span> <span class="o">+</span>                     <span class="s1">&#39;/test_big_file_offsite_write_random_write&#39;</span>
        <span class="n">os</span><span class="o">.</span><span class="n">system</span><span class="p">(</span> <span class="s1">&#39;cp </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">inited_bigfile</span><span class="p">,</span> <span class="n">bigfile</span><span class="p">)</span> <span class="p">)</span>
        <span class="n">os</span><span class="o">.</span><span class="n">system</span><span class="p">(</span> <span class="s1">&#39;cp </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">bigfile</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tmpfile</span><span class="p">)</span> <span class="p">)</span>
        <span class="n">times</span> <span class="o">=</span> <span class="mi">50</span>
        <span class="n">baseOffsite</span> <span class="o">=</span> <span class="mi">1000</span>
        <span class="n">fp0</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">bigfile</span><span class="p">,</span> <span class="s1">&#39;r+b&#39;</span><span class="p">)</span>
        <span class="n">fp1</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tmpfile</span><span class="p">,</span> <span class="s1">&#39;rb+&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">xrange</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span> <span class="n">times</span> <span class="p">):</span>
            <span class="n">fp0</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="n">baseOffsite</span><span class="p">)</span>
            <span class="n">fp1</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="n">baseOffsite</span><span class="p">)</span>
            <span class="n">fp0</span><span class="o">.</span><span class="n">write</span><span class="p">(</span> <span class="s1">&#39;a&#39;</span> <span class="o">*</span> <span class="mi">100</span> <span class="p">)</span>
            <span class="n">fp1</span><span class="o">.</span><span class="n">write</span><span class="p">(</span> <span class="s1">&#39;a&#39;</span> <span class="o">*</span> <span class="mi">100</span> <span class="p">)</span>
            <span class="n">baseOffsite</span> <span class="o">+=</span> <span class="mi">1000</span>
        <span class="n">fp0</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="n">fp1</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_check_filemd5</span><span class="p">(</span><span class="n">bigfile</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tmpfile</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">teardown</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_result</span><span class="p">():</span>
            <span class="c1"># if case succeeded, do sth</span>
            <span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tmpfile</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_clearman</span><span class="o">.</span><span class="n">teardown</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># if case failed, do sth else.</span>
            <span class="nb">print</span> <span class="s1">&#39;failed&#39;</span>
        <span class="n">cup</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span> <span class="s1">&#39;End running &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="vm">__file__</span> <span class="p">)</span> <span class="p">)</span>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">cup</span><span class="o">.</span><span class="n">unittest</span><span class="o">.</span><span class="n">CCaseExecutor</span><span class="p">()</span><span class="o">.</span><span class="n">runcase</span><span class="p">(</span><span class="n">TestMyCase</span><span class="p">())</span>
</pre></div>
</div>
<dl class="classmethod">
<dt id="cup.unittest.CCaseExecutor.runcase">
<em class="property">classmethod </em><code class="descname">runcase</code><span class="sig-paren">(</span><em>case</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#CCaseExecutor.runcase"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.CCaseExecutor.runcase" title="Permalink to this definition">¶</a></dt>
<dd><p>run the case</p>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="cup.unittest.expect_raise">
<code class="descclassname">cup.unittest.</code><code class="descname">expect_raise</code><span class="sig-paren">(</span><em>function</em>, <em>exception</em>, <em>*argc</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/cup/unittest/#expect_raise"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.unittest.expect_raise" title="Permalink to this definition">¶</a></dt>
<dd><p>expect raise exception</p>
</dd></dl>

</div>
<div class="section" id="module-cup.version">
<span id="cup-version-module"></span><h2>cup.version module<a class="headerlink" href="#module-cup.version" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">desc:</th><td class="field-body">CUP version for Programming Use Only.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="module-cup">
<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-cup" title="Permalink to this headline">¶</a></h2>
<p>&#64;author Guannan Ma</p>
</div>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../cup.net/" class="btn btn-neutral float-right" title="cup.net package" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="../" class="btn btn-neutral" title="Welcome to cup’s documentation!" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, CUP-DEV.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../',
            VERSION:'1.7.0',
            LANGUAGE:'en',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../_static/jquery.js"></script>
      <script type="text/javascript" src="../_static/underscore.js"></script>
      <script type="text/javascript" src="../_static/doctools.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  <script type="text/javascript" src="../_static/js/theme.js"></script>

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>